using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using NCS.Module.CMS.Library;
using NCS.Library.Utilities;
using NCS.Module.CMS.Library.Sport;

namespace NCS.Module.CMS.Web.Sport
{
    public partial class RightPosition2 : CMSWebControl
    {
        private int seasonid =0;
        //private int i = 0;
        private int total = 0;
        protected void Page_Load(object sender, EventArgs e)
        {
            int catid = ConvertUtility.ToInt32(Request.QueryString["catid"]);
            if (catid != 0)
            {
                Advertisement1.Param = "catid";
            }
            if (!IsPostBack)
            {                
                dropSeason.DataSource = SeasonController.SoccerSeason_GetAll(true);
                dropSeason.DataBind();
            }
            if (seasonid > 0)
                dropSeason.SelectedValue = seasonid.ToString();               
            
        }

        protected override void OnPreRender(EventArgs e)
        {
            base.OnPreRender(e);
            if (seasonid == 0)
                seasonid = ConvertUtility.ToInt32(dropSeason.SelectedValue);
            
            DataTable match = MatchController.Match_GetAll(seasonid, true);
            total = match.Rows.Count;
            //if(total==0)
            //    lbload.Text = "<script language=\"javascript\">hidden();</script>";
            //else
            //    lbload.Text = "<script language=\"javascript\">display();</script>";
            rptmatch.DataSource = match;
            rptmatch.ItemDataBound += new RepeaterItemEventHandler(rptmatch_ItemDataBound);
            rptmatch.DataBind();
            
        }

        protected void dropSeason_SelectedIndexChanged(object sender, EventArgs e)
        {
            seasonid = ConvertUtility.ToInt32(dropSeason.SelectedValue);
        }

        protected void rptmatch_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemIndex < 0)                       
                return;            
            DataRowView currow = (DataRowView)e.Item.DataItem;
            HyperLink hplmatch = (HyperLink)e.Item.FindControl("hplmatch");
            HyperLink hpltime = (HyperLink)e.Item.FindControl("hpltime");

            hplmatch.Text = currow["Match_Name"].ToString();
            hplmatch.NavigateUrl = Request.RawUrl + "#";
            hpltime.Text = ConvertUtility.ToDateTime(currow["Match_Time"]).ToString("hh:mm");
            hpltime.NavigateUrl = Request.RawUrl + "#";
            //i++;
            //if (i == total)
            //    lbload.Text = "<script language=\"javascript\">hidden();</script>";
        }
    }
}